// list.js
var app = getApp();
Page({
  data: {
    city: wx.getStorageSync('companyinfo').city,
    isCars: true,	// 选择车源开关
    isSort: true,	// 选择排序开关
    isPrice: true,	// 选择价格开关
    isType: true,
    isSelect:true,
    loadMore: '',
    list: [],
    house_list: [],
    housetypelist: [],
    houseareaid: 0,
    housepriceid: 0,
    housetype: 0, 
    letway:0,
    page: 1,
    title: ''
  },
  // 首屏渲染
  onLoad(params) {
    var that = this;
    // var data = { 'name': '住宅', 'id': 1 };
    var housetypelist = [
      { 'name': '1室', 'id': 1 },
      { 'name': '2室', 'id': 2 },
      { 'name': '3室', 'id': 3 },
      { 'name': '4室', 'id': 4 },
      { 'name': '5室', 'id': 5 },
      { 'name': '5室以上', 'id': 6 }
      ];
    var housewaylist = [
      { 'name': '整租', 'id': 1 },
      { 'name': '合租', 'id': 2 }
    ];
    //  housetypelist.push(data);
    
    var carid = 0;
    var priceid = 0;
    var typeid =0;
    var selectid = 0;
    this.setData({ housetypelist: housetypelist,carid:carid,priceid:priceid,typeid:typeid, selectid: selectid, housewaylist: housewaylist});
    wx.setNavigationBarTitle({
      title: '房屋出租-' + wx.getStorageSync('companyinfo').name,
    })
    app.util.request({
      'url': 'entry/wxapp/getinitletinfo',
      success: function (res) {
        if (!res.data.message.errno) {
          that.setData({
            city: wx.getStorageSync('companyinfo').city,
            arealist: res.data.data.arealist,
            housepricelist: res.data.data.housepricelist,
            title: '',
            price: '',
            typetitle: '',
            selecttitle:''
          })
        }
      },
      complete: function () {

      
      }
    });

    app.util.request({
      'url': 'entry/wxapp/getlethouselist',
      data: { houseareaid: that.data.houseareaid, housepriceid: that.data.housepriceid, housetype: that.data.housetype, letway: that.data.letway },
      success: function (res) {
        if (!res.data.message.errno) {
          console.log(res.data.data);
          that.setData({
            houselist: res.data.data,

          })
        }
      },
      complete: function () {
        wx.hideNavigationBarLoading(); //完成停止加载
        wx.stopPullDownRefresh();
        that.setData({
          loadMore: ''
        })

      }
    });
  },

  toHouseDetail: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/weixinmao_house/pages/lethousedetail/index?id=" + id
    })

  }
  ,
  toSearch: function (e) {
    wx.navigateTo({
      url: "/weixinmao_house/pages/search/index"
    })

  }
  ,
  gethouselist: function (e) {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/getlethouselist',
      data: { page: that.data.page, houseareaid: that.data.houseareaid, housepriceid: that.data.housepriceid, housetype: that.data.housetype, letway: that.data.letway },
      success: function (res) {
        if (!res.data.message.errno) {
          console.log(res.data.data);
          that.setData({
            houselist: res.data.data,

          })
        }
      },
      complete: function () {
        that.setData({
          loadMore: ''
        })

      }
    });


  },
  selectcarsitem: function (e) {
    var carid = e.currentTarget.id;
    var title = e.currentTarget.dataset.title;
    this.setData({ carid: carid, isCars: true, title: title });
    this.data.houseareaid = carid;
    this.gethouselist();

  }
  ,
  selectpriceitem: function (e) {
    console.log(e.currentTarget.id);
    var priceid = e.currentTarget.id;
    var title = e.currentTarget.dataset.title;
    this.setData({ priceid: priceid, isPrice: true, price: title });
    this.data.housepriceid = priceid;
    this.gethouselist();
  }
  ,
  selecttypeitem: function (e) {
    var typeid = e.currentTarget.id;
    var title = e.currentTarget.dataset.title;
    console.log(e.currentTarget);
    this.setData({ typeid: typeid, isType: true, typetitle: title });
    this.data.housetype = typeid;
    this.gethouselist();
  },
  selectwayitem: function (e) {
    console.log(e.currentTarget.id);
    var selectid = e.currentTarget.id;
    var title = e.currentTarget.dataset.title;
    console.log(e.currentTarget);
    this.setData({ selectid: selectid, isSelect: true, selecttitle: title });
    this.data.letway = selectid;
    this.gethouselist();
  },
  // 下拉加载
  onReachBottom(params) {
    var that = this;
    that.setData({
      loadMore: '正在加载中...'
    })
    this.data.page = this.data.page + 1;
    this.gethouselist();
  },
  // 点击搜索
  clickSearch: function (e) {
    wx.switchTab({
      url: '/pages/search/search'
    })
  },
  // 点击列表
  clickList: function () {
    wx.navigateTo({
      url: '../cars/cars'
    })
  },
  // 选择排序方式
  selectCars: function (e) {
    var that = this;
    that.setData({
      isSort: true,
      isPrice: true,
      isType: true,
      isSelect: true,
      isCars: (!that.data.isCars)
    })
  },
  selectPrice: function () {
    var that = this;
    console.log('aaa');
    that.setData({
      isSort: true,
      isCars: true,
      isType: true,
      isSelect: true,
      isPrice: (!that.data.isPrice)
    })
  },
  selectType: function () {
    var that = this;
    that.setData({
      isSort: true,
      isCars: true,
      isPrice: true,
      isSelect:true,
      isType: (!that.data.isType)
    })
  },
  selectWay: function () {
    var that = this;
    that.setData({
      isSort: true,
      isCars: true,
      isPrice: true,
      isType: true,
      isSelect: (!that.data.isSelect)
    })
  },
  selectSort: function () {
    var that = this;
    that.setData({
      isCars: true,
      isPrice: true,
      isType: true,
      isSort: (!that.data.isSort)
    })
  },
  selectBrand: function () {
    wx.navigateTo({
      url: '../brand/brand'
    })
  }, onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    this.onLoad();
  },
  // 分享
  onShareAppMessage: function () {
    return {
      title: '房屋出租-' + wx.getStorageSync('companyinfo').name,
      path: '/weixinmao_house/pages/lethouselist/index'
    }
  }
})